package link.ten_fei.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import link.ten_fei.Bean.Pl_Num;
import link.ten_fei.util.ConnectionFactory;

public class ShowDaoImpl implements ShowDao {
	public List<Pl_Num> show() {
		Connection connection = ConnectionFactory.getConnection();
		PreparedStatement preparedStatement = null;
		ResultSet rs = null;
		try {
			String sql = "select pl_doctor , count(*) as sum from pl_list ,doc_user where pl_doctor=doc_name and doc_judge!=0 group by pl_doctor";
			preparedStatement = connection.prepareStatement(sql);
			rs = preparedStatement.executeQuery();
			List<Pl_Num> lists = new ArrayList<Pl_Num>();
			while (rs.next()) {
				Pl_Num pl_Num = new Pl_Num();
				pl_Num.setDoc_name(rs.getString("pl_doctor"));
				pl_Num.setDoc_num(Integer.parseInt(rs.getString("sum")));
				lists.add(pl_Num);
			}
			return lists;
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ConnectionFactory.close(connection, preparedStatement, rs);
		}
		return null;
	}
}
